/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package weka;

import java.awt.BorderLayout;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JPanel;
import weka.classifiers.trees.J48;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.gui.treevisualizer.PlaceNode2;
import weka.gui.treevisualizer.TreeVisualizer;

/**
 *
 * @author JeanW
 */
public class Visualisation {
    private TreeVisualizer tv;

    public Visualisation(String text){
        
        DataSource source = null;
        try {
            source = new DataSource(text);
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    Instances data = null;
        try {
            data = source.getDataSet();
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    if (data.classIndex() == -1)
      data.setClassIndex(data.numAttributes() - 1);
    J48 base = new J48();
        try {
            base.buildClassifier(data);
        } catch (Exception ex) {
            Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {
            tv = new TreeVisualizer(null,
    base.graph(),
     new PlaceNode2());
            } catch (Exception ex) {
                Logger.getLogger(VisualisationAction.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    
    public TreeVisualizer getTree(){
        return this.tv;
    }
    
}
